<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8"/>
        <title>入库页面</title>
        <meta content="webkit" name="renderer"/>
        <link href="../../css/font.css" rel="stylesheet"/>
        <link href="../../css/xadmin.css" rel="stylesheet"/>
        <script charset="utf-8" src="../../lib/layui/layui.js"></script>
        <script src="../../js/xadmin.js" type="text/javascript"></script>
        <script src="../../js/vue2.7min.js"></script>
        <script src="../../js/axios.min.js"></script>
    </head>
    <body>
        <div class="x-nav">
            <a
                    class="layui-btn layui-btn-small"
                    onclick="location.reload()"
                    style="line-height: 1.6em; margin-top: 3px; float: right"
                    title="刷新"
            >
                <i class="layui-icon layui-icon-refresh" style="line-height: 30px"></i
                ></a>
        </div>
        <div class="layui-fluid" id="app">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <button
                                class="layui-btn"
                                v-if="managerLevel===0"
                                @click="downloadExcel()">
                            <i class="layui-icon"></i>导出Excel
                        </button>
                        <div class="layui-card-body layui-table-body layui-table-main">
                            <table class="layui-table layui-form">
                                <thead>
                                <tr>
                                    <th>编号</th>
                                    <th>操作编号</th>
                                    <th>入库操作者id</th>
                                    <th>入库操作者Name</th>
                                    <th>商品编号</th>
                                    <th>商品名称</th>
                                    <th>仓库编号</th>
                                    <th>仓库名称</th>
                                    <th>入库数量</th>
                                    <th>入库时间</th>
                                </tr>
                                </thead>
                                <tbody>

                                <!--模板开始-->
                                <tr v-for="(item , index) in records">
                                    <td>{{index+1}}</td>
                                    <td v-text="item.buyId"></td>
                                    <td v-text="item.buyMasterId"></td>
                                    <td v-text="item.buyMasterName"></td>
                                    <td v-text="item.buyGoodsId"></td>
                                    <td v-text="item.buyGoodsName"></td>
                                    <td v-text="item.buyWarehouseId"></td>
                                    <td v-text="item.buyWarehouseName"></td>
                                    <td v-text="item.buyNumber"></td>
                                    <td v-text="item.createTime"></td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                        <div class="layui-card-body">
                            <div class="page">
                                <div>
                                    <a class="prev"
                                       @click="getPage('-')">&lt;&lt;</a>
                                    <a class="num" v-text="current-1" v-if="current>1"
                                       @click="getPage('-')"></a>

                                    <span class="current" v-text="current"></span>

                                    <a class="num" v-text="current+1" v-if="current<pages"
                                       @click="getPage('+')"></a>
                                    <a class="num" v-text="pages" v-if="current+1 < pages"
                                       @click="getPage('max')"></a>

                                    <a class="next"
                                       @click="getPage('+')">&gt;&gt;</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <script type="text/javascript">
            var vm = new Vue({
                el: "#app",
                data: {
                    //分页属性
                    current: 1,
                    records: null,
                    total: null,
                    size: null,
                    pages: null,
                    //入库buy属性
                    buyId: null,
                    buyMasterId: null,
                    buyGoodsId: null,
                    buyWarehouseId: null,
                    buyNumber: null,
                    createTime:null,
                    updateTime:null,
                    createUser:null,
                    updateUser:null,
                    //Manager信息
                    managerId: null,
                    managerName: null,
                    managerPassword: null,
                    managerRealName: null,
                    managerSex: null,
                    managerPhone: null,
                    managerState: null,
                    managerLevel: null,


                },
                methods: {
                    getPage(str) {
                        var jsonD = null;
                        if (str === "first") {
                            //默认查询第一页
                            jsonD = {num1: 1}
                        } else {
                            //不是第一次
                            var aimCurrent = null;
                            if (vm === null || vm.current === null) {
                                aimCurrent = 1;
                            } else {
                                aimCurrent = vm.current;
                            }
                            //判断参数操作符好
                            if (str === '-') {
                                if (vm.current === 1) {
                                    aimCurrent = 1;
                                } else {
                                    aimCurrent = aimCurrent - 1;
                                }
                            } else if (str === '+') {
                                if (vm.current < vm.pages) {
                                    aimCurrent = aimCurrent + 1;
                                } else {
                                    aimCurrent = vm.pages;
                                }
                            } else if (str === 'max') {
                                aimCurrent = vm.pages;
                            }
                            jsonD = {num1: aimCurrent}
                        }
                        axios.post("../../../buy/getPageByLevel", jsonD)
                            .then(function (response) {
                                vm.current = response.data.data.current;
                                vm.records = response.data.data.records;
                                vm.total = response.data.data.total;
                                vm.size = response.data.data.size;
                                vm.pages = response.data.data.pages;

                            }, function (err) {
                                console.log(err);

                            })

                    },
                    downloadExcel() {
                        axios.post("../../../excel/downloadBuyExcel")
                            .then(function (response) {
                                layer.alert("文件导出成功" +
                                    "文件地址：D:red1/excel/", {
                                    icon: 6
                                })
                            }, function (err) {
                                console.log(err);

                            })
                    },
                    //获取管理员信息
                    getManager() {
                        axios.post("../../../manager/getManager")
                            .then(function (response) {
                                //数据保存到vue全局
                                if (response.data.code === 1) {
                                    //Manager信息
                                    vm.managerId = response.data.data.managerId;
                                    vm.managerName = response.data.data.managerName
                                    vm.managerPassword = response.data.data.managerPassword
                                    vm.managerRealName = response.data.data.managerRealName
                                    vm.managerSex = response.data.data.managerSex
                                    vm.managerPhone = response.data.data.managerPhone
                                    vm.managerState = response.data.data.managerState
                                    vm.managerLevel = response.data.data.managerLevel
                                }
                            }, function (err) {
                                console.log(err);

                            })
                    },

                },
                mounted: function () {
                    //查询管理员信息
                    this.getManager();
                    //获取分页信息
                    this.getPage("first");
                }
            });
        </script>
    </body>

</html>
